Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

test: refactor mock api server to fail on error #141

Merged
merged 2 commits into from
Oct 31, 2023
Merged

test: refactor mock api server to fail on error #141

merged 2 commits into from
Oct 31, 2023

Conversation

m90
Copy link
Contributor

@m90 m90 commented Oct 30, 2023

Connects #139

The mock api service relies on the wikibase service being up. Currently they are racing, and the mock api keeps crashing because of an unhandled promise rejection until wikibase is up.

When adding additional logic in #139, this fail-forward approach does not work anymore as the seeding fails to win the race against the retry logic.

This PR does two things:

  • prevent the mock api from crashing on errors
  • declare inter-service dependencies properly so that api is ready when being called

@m90 m90 force-pushed the fr/test-mock-api branch 2 times, most recently from af9b6ef to 1c85de4 Compare October 30, 2023 13:43
@m90 m90 force-pushed the fr/test-mock-api branch 7 times, most recently from 562f56e to f40e6e5 Compare October 30, 2023 15:32
@m90 m90 force-pushed the fr/test-mock-api branch from f40e6e5 to f400633 Compare October 30, 2023 15:36
@m90 m90 marked this pull request as ready for review October 30, 2023 15:46
@@ -17,4 +17,4 @@ DB_PASS=change-this-sqlpassword
WIKIBASE_PINGBACK=false
# wikibase.svc is the internal docker hostname, change this value to the public hostname
WIKIBASE_HOST=wikibase.svc
WIKIBASE_PORT=80
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Not sure if this has some background, but I cannot bind to port 80 locally using docker compose unless I elevate priviliges.

Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think there is no reason to keep this like it is; I guess it was just picked at some point to look closest to prod. After all these port names end up in the URIs of the triples that go in the queryservice

@@ -1,18 +1,5 @@
version: '2'
services:

wikibase:
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I don't really know what these overrides are good for. Containers can use the Docker network (instead of the host one) in both CI and local testing.

Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

no clue either.. let's not keep it

@@ -1,41 +1,52 @@
var http = require('http');
const wbEdit = require( 'wikibase-edit' )( require( './wikibase-edit.config' ) );

var x = 0
http.createServer(async function (req, res) {
res.writeHead(200, {'Content-Type': 'text/json'});
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Having this as the first line meant we'd 200 even when wikibase was still down.

Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

nice catch

res.end(JSON.stringify([responseObject]));
return;
default:
res.writeHead(404);
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I like this; good idea to ensure it 404s everywhere else

Copy link

@tarrow tarrow left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Looks good to me. I understand how this resolve the race between wikibase and the fake api. I'm not quite sure I understand how our test "passes by accident" before this though; perhaps if I don't get my head around it tomorrow you can explain.

@m90
Copy link
Contributor Author

m90 commented Oct 31, 2023

"passes by accident" was badly phrased when I did not understand every detail of this yet. What happens is that the previous tests relied on an intricate choreography of retries and server restarts that stopped working when more requests were made against the failing server.

@m90 m90 merged commit 0a7d8a0 into main Oct 31, 2023
4 checks passed
@m90 m90 deleted the fr/test-mock-api branch October 31, 2023 07:31
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants